﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using YJKRevitWndr.InsertDoorAndWindow.InsertOperation;
using YArchitech.Controls;

namespace YJKRevitWndr.InsertDoorAndWindow.Cmd
{
	public class HideWarningKit
	{
		public HideWarningKit(List<string> transactionNames)
		{
			this.m_TransactionNames = transactionNames;
		}

		public void OnFailuresProcessing(object sender, FailuresProcessingEventArgs e)
		{
			FailuresAccessor failuresAccessor = e.GetFailuresAccessor();
			string transactionName = failuresAccessor.GetTransactionName();
			IList<FailureMessageAccessor> failureMessages = failuresAccessor.GetFailureMessages();
			if (failureMessages.Count == 0)
			{
				e.SetProcessingResult((FailureProcessingResult)0);
				return;
			}
			if (this.m_TransactionNames.Contains(transactionName))
			{
				foreach (FailureMessageAccessor failureMessageAccessor in failureMessages)
				{
                    int severity = (int)failureMessageAccessor.GetSeverity();
					List<ElementId> list = new List<ElementId>();
					List<ElementId> list2 = new List<ElementId>();
					if (severity == 1)
					{
						if (InsertDoorAndWindowManage.g_OverlapElemId != ElementId.InvalidElementId)
						{
							list2.Add(InsertDoorAndWindowManage.g_OverlapElemId);
							failuresAccessor.DeleteElements(list2);
							YJKMessageBox.Show("与已有对象重叠,无法布置！", MessageBoxButtons.OK);
						}
						failuresAccessor.DeleteWarning(failureMessageAccessor);
					}
					else
					{
						if (failureMessageAccessor.GetFailingElementIds().Count > 0)
						{
							if (transactionName == "ModifySymbol")
							{
								list.Add(InsertDoorAndWindowManage.g_NewSymbolId);
								failuresAccessor.DeleteElements(list);
								YJKMessageBox.Show("窗宽或窗高数据不合格，无法生成类型");
							}
							e.SetProcessingResult((FailureProcessingResult)1);
							return;
						}
						e.SetProcessingResult((FailureProcessingResult)2);
					}
				}
				return;
			}
			e.SetProcessingResult((FailureProcessingResult)0);
		}

		private List<string> m_TransactionNames = new List<string>();
	}
}
